package csc.fresher.currency.convertor;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.ConverterException;
import javax.faces.convert.FacesConverter;
import javax.faces.convert.IntegerConverter;

@FacesConverter("digitsOnly")
public class DigitsOnlyConverter extends IntegerConverter {

    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) throws ConverterException {
        if (!value.matches("\\d*")) {
            throw new ConverterException();
        }

        return super.getAsObject(context, component, value);
    }

}